from django.shortcuts import render, HttpResponse
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_protect, csrf_exempt
from django.views import View


# Create your views here.


def index(request):
    print('视图函数index')
    return HttpResponse('index')


@csrf_exempt
def transfer(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        target_user = request.POST.get('target_user')
        money = request.POST.get('money')
        print(f'{username}给{target_user}转了{money}元')
    return render(request, 'transfer.html')


# @method_decorator(csrf_protect, name='post')  可行
class MyCsrfToken(View):
    @method_decorator(csrf_protect)
    def dispatch(self, request, *args, **kwargs):
        return super(MyCsrfToken, self).dispatch(request, *args, **kwargs)

    def get(self, request):
        return

    # @method_decorator(csrf_protect)  可行
    def post(self, request):
        return